package ar.com.viajes.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import ar.com.viajes.dao.CiudadDao;
import ar.com.viajes.dao.EmpresaDao;
import ar.com.viajes.dao.ViajeDao;
import ar.com.viajes.dao.imp.CiudadDaoImpl;
import ar.com.viajes.dao.imp.EmpresaDaoImpl;
import ar.com.viajes.dao.imp.ViajeDaoImpl;
import ar.com.viajes.form.ViajeAbmForm;
import ar.com.viajes.services.ServiceFacade;
import ar.com.viajes.services.SpringUtil;

public class BusquedaCiudadEmpresa extends DispatchAction {
	public ActionForward preBusqueda(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ServiceFacade facade =(ServiceFacade)SpringUtil.getBean("serviceFacade");
		ViajeAbmForm viajeAbmForm = (ViajeAbmForm) form;


		request.setAttribute("listaCiudad", facade.getCiudadDao().getAll());
		request.setAttribute("listaEmpresa", facade.getEmpresaDao().getAll());

		viajeAbmForm.setEvent("busqueda");
		return mapping.findForward("preBusqueda");

	}

	public ActionForward busqueda(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ServiceFacade facade =(ServiceFacade)SpringUtil.getBean("serviceFacade");
		ViajeAbmForm viajeAbmForm = (ViajeAbmForm) form;
		request.setAttribute("listaCiudad", facade.getCiudadDao().getAll());
		request.setAttribute("listaEmpresa", facade.getEmpresaDao().getAll());
	
		request.setAttribute("listaViajefiltrado", facade.getViajeDao().obtenerViajeXEmpresaCiudad(viajeAbmForm.getEmpresaId(),viajeAbmForm.getCiudadId()));
		return mapping.findForward("busqueda");

	}

}
